package job

import (
	"github.com/wagslane/go-rabbitmq"
	"log"
)

type Product struct {
}

func NewProduct() *Product {
	return &Product{}
}

func (p *Product) Order() {
	conn, err := NewRabbitMQConn(mqUrl, rabbitmq.WithConnectionOptionsLogging)

	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	publisher, err := NewRabbitMQPublisher(conn,
		rabbitmq.WithPublisherOptionsLogging,
		rabbitmq.WithPublisherOptionsExchangeName("Yii"),
		rabbitmq.WithPublisherOptionsExchangeDeclare)

	if err != nil {
		log.Fatal(err)
	}
	defer publisher.Close()

	err = publisher.Publish(
		[]byte("13053011580"),
		[]string{"routing_yii"},
		rabbitmq.WithPublishOptionsContentType("application/json"),
		rabbitmq.WithPublishOptionsExchange("Yii"),
	)
	if err != nil {
		log.Println(err)
	}
}
